home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** Routines demonstrating how to launch an application without from a Time
- ** Manager task which calls a Notification Manager task.
- **
- ** by Mark Cookson, and Pete Gontier, Apple Developer Technical Support
- **
- ** File: LaunchMeFRAG.c
- **
- ** Copyright ©1996 Apple Computer, Inc.
- ** All rights reserved.
- **
- ** You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "Apple Sample
- ** Code" after having made changes. If you're going to re-distribute the
- ** source, we require that you make it clear in the source that the code
- ** was descended from Apple Sample Code, but that you've made changes.
- */
-
- #include "LaunchMe.h"
-
- #ifndef __Assembler__
- # include <Assembler.h>
- #endif
-
- /* This function is the Notification Manager task that will be called.
- LaunchApplication() can be called safely from a Notification Manager call, but
- not from a Time Manager task which is why the Time Manager task makes a
- Notification Manager task to launch the application.
-
- This routine removes the notification, and the launch info pointer from
- the system heap and then calls a routine that will remove the code segement
- from the system heap.
- */
- static pascal Handle NMResponder (NMRecPtr nmrp)
- {
- void __Startup__ (void);
-
- MyDelayedLaunchPtr launchInfo = (MyDelayedLaunchPtr) nmrp->nmRefCon;
-
- (void)LaunchApplication (&(launchInfo->launchMe)); // Not much we could do about an error now.
- NMRemove (nmrp);
- DisposePtr ((Ptr)launchInfo);
-
- return RecoverHandle ((Ptr) __Startup__);
- }
-
- static pascal asm void NMResponderAsm (void)
- {
- //
- // By Pete Gontier
- //
- // This function takes a parameter on the stack, but we
- // don't declare it at the C level so the compiler doesn't
- // know about it. That's fine, as long as we are willing to
- // do the extra work, and we are.
- //
-
- CLR.L -(A7) // NMResponder return value
- MOVE.L 8(A7),-(A7) // parameter to NM response func
- JSR NMResponder // call the real NM task
- MOVE.W #_DisposeHandle,D0 // _GetTrapAddress parameter
- _GetTrapAddress | newOSTrap
- MOVE.L A0,A1 // _GetTrapAddress return value
- MOVE.L (A7)+,A0 // NMResponder return value to DisposeHandle
- MOVE.L (A7),4(A7) // copy our return address over our parameter
- ADDQ.L #4,A7 // dump extra return address
- JMP (A1) // "call trap" DisposeHandle
-
- //
- // All this hackiness has called DisposeHandle such that it will
- // return to whoever called us; we never get control back, which
- // is exactly what we want, since we are disposing the handle
- // which contains our code.
- //
- }
-
- pascal void main (MyDelayedLaunchPtr passedPtr:__a1)
- {
- RmvTime ((QElemPtr) passedPtr);
-
- passedPtr->NMProcRec.qType = 8;
- passedPtr->NMProcRec.nmMark = 0;
- passedPtr->NMProcRec.nmIcon = nil;
- passedPtr->NMProcRec.nmSound = nil;
- passedPtr->NMProcRec.nmStr = nil;
- // This is a pointer to our cool clean up routine so that we don't leave an orphaned
- // block of code in the system heap.
- passedPtr->NMProcRec.nmResp = (NMProcPtr) NMResponderAsm;
- passedPtr->NMProcRec.nmRefCon = (long)passedPtr;
-
- NMInstall (&passedPtr->NMProcRec);
- }
-